<div class="content">
    <div id="example_title">
        <h1>Main -> Details</h1>
        There is a number of different events you can listen to in the grid. The example below demonstrates how to implement a simple
        main -> detail list. In the example the grids use local data, but there is no restriction on this.
    </div>
    <div id="example_view"></div>
    <div id="example_code"></div>
</div>

<!--CODE-->
<div style="position: relative; height: 300px;">
    <div id="grid1" style="display: inline-block; width: 500px; height: 300px;"></div>
    <div id="grid2" style="display: inline-block; width: 500px; height: 300px;"></div>
</div>

<!--CODE-->
<script type="module">
import { w2grid } from '__W2UI_PATH__'

let grid = new w2grid({
    name: 'grid1',
    box: '#grid1',
    header: 'Main',
    show: { header: true },
    columns: [
        { field: 'recid', text: 'ID', size: '50px', sortable: true, attr: 'align=center' },
        { field: 'lname', text: 'Last Name', size: '30%', sortable: true },
        { field: 'fname', text: 'First Name', size: '30%', sortable: true },
        { field: 'email', text: 'Email', size: '40%' },
        { field: 'sdate', text: 'Start Date', size: '120px' }
    ],
    records: [
        { recid: 1, fname: 'John', lname: 'Doe', email: 'jdoe@gmail.com', sdate: '4/3/2012' },
        { recid: 2, fname: 'Stuart', lname: 'Motzart', email: 'motzart@hotmail.com', sdate: '4/3/2012' },
        { recid: 3, fname: 'Jin', lname: 'Franson', email: 'jin@yahoo.com', sdate: '4/3/2012' },
        { recid: 4, fname: 'Susan', lname: 'Ottie', email: 'sottie@yahoo.com', sdate: '4/3/2012' },
        { recid: 5, fname: 'Kelly', lname: 'Silver', email: 'kelly@gmail.com', sdate: '4/3/2012' },
        { recid: 6, fname: 'Francis', lname: 'Gatos', email: 'frank@apple.com', sdate: '4/3/2012' }
    ],
    onClick(event) {
        let record = this.get(event.detail.recid)
        grid2.clear()
        grid2.add([
            { recid: 0, name: 'ID:', value: record.recid },
            { recid: 1, name: 'First Name:', value: record.fname },
            { recid: 2, name: 'Last Name:', value: record.lname },
            { recid: 3, name: 'Email:', value: record.email },
            { recid: 4, name: 'Date:', value: record.sdate }
        ])
    }
})

let grid2 = new w2grid({
    name: 'grid2',
    box: '#grid2',
    header: 'Details',
    show: { header: true, columnHeaders: false },
    name: 'grid2',
    columns: [
        { field: 'name', text: 'Name', size: '100px', style: 'background-color: #efefef; border-bottom: 1px solid white; padding-right: 5px;', attr: "align=right" },
        { field: 'value', text: 'Value', size: '100%' }
    ]
})
</script>
